package com.yd.app.mapper;

import com.yd.app.mapper.provider.DicProvider;
import com.yd.domain.business.GType;
import com.yd.domain.sys.Dic;
import com.yd.domain.searchParam.DicParam;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zy
 * @create 2018-03-07 17:45
 * @desc 数据字典
 **/
@Repository
public interface DicMapper {
    /**
     * @Author: zy
     * @Desc:新增字典
     * @Date:  2018/3/7
     **/
    @Insert("INSERT INTO sys_dic (id,`code`,des,title,type) VALUES(#{dic.id},#{dic.code},#{dic.des},#{dic.title},#{dic.type})")
    void addDic(@Param("dic")Dic dic);
    /**
     * @Author: zy
     * @Desc:权限的分页查询数据
     * @Date:  2018/3/7
     */
    @SelectProvider(method = "searchDicList",type= DicProvider.class)
    List<Dic> searchDicList(@Param("dicParam") DicParam dicParam, @Param("startRow") int startRow, @Param("pageSize") int pageSize);
    /**
     * @Author: zy
     * @Desc:权限查询数量
     * @Date:  2018/3/7
     */
    @SelectProvider(method = "searchDicCount",type= DicProvider.class)
    int searchDicCount(@Param("dicParam") DicParam dicParam);
    /**
     * @Author: zy
     * @Desc: 根据类型获取字典数据
     * @Date:  2018/3/8
     */
    @Select("select * from sys_dic where type=#{type} ")
    List<Dic> getDicListByType(@Param("type") String type);
    /**
     * @Author: zy
     * @Desc: 修改数据字典
     * @Date:  2018/3/8
     * @Param
     */
    @Update("update sys_dic set `code`=#{dic.code},des=#{dic.des},title=#{dic.title},type=#{dic.type} where  id=#{dic.id} ")
    void updateDic(@Param("dic") Dic dic);
    /**
     * @Author: zy
     * @Desc: 删除数据字典
     * @Date:  2018/3/8
     * @Param
     */
    @Delete("delete from sys_dic where id=#{id}")
    void deleteDic(@Param("id") String id);

    @Select("select * from business_gtype order by goodKind  ")
    List<GType> getGTypeList();

    /**
     * 启用停用gtype
     * @param id
     * @param ifUse
     */
    @Update("update business_gtype set ifUse=#{ifUse} where id=#{id} ")
    void enableGType(@Param("id") String id, @Param("ifUse") boolean ifUse);

    @Insert("insert into business_gtype (id,typeName,price,ifUse,goodKind,iconUrl,pId) values (#{g.id},#{g.typeName},#{g.price},#{g.ifUse},#{g.goodKind},#{g.iconUrl},#{g.pId})  ")
    void addGType(@Param("g") GType gType);

    @Update("update business_gtype set typeName=#{g.typeName},price=#{g.price},goodKind=#{g.goodKind},iconUrl=#{g.iconUrl},pId=#{g.pId} where id=#{g.id} ")
    void updateGTpye(@Param("g") GType gType);
}
